#include <iostream>
#include <stdlib.h>

using namespace std;

const int N = int(1e6 + 10);

int q[N];
int top, tail;

bool empty()
{
	return top == tail;
}

bool full()
{
	return (tail + 1 - top) % N == 0;
}

int length(void)
{
	return (tail + N - top) % N;
}

void push(int x)
{
    if (full())
    {
        printf("队列已满\n");
        exit(EXIT_FAILURE);
    }
    q[tail] = x;
    tail = (tail + 1) % N;
}

int query(void)
{
    if (empty())
    {
        printf("队列为空, 无数据可访问\n");
        exit(EXIT_FAILURE);
    }
    return q[top];
}

int pop(void)
{
    if (empty())
    {
        printf("队列为空, 无数据可删除");
        exit(EXIT_FAILURE);
    }
    int tmp = q[top];
    top = (top + 1) % N;
    return tmp;
}

int main(void)
{
    int m, x;
    char s[20];
    scanf("%d", &m);

    while (m--)
    {
        scanf("%s", s);
        if (s[3] == 'h')
        {
            scanf("%d", &x);
            push(x);
        }
        else if (s[3] == '\0')
            pop();
        else if (s[3] == 't')
            printf("%s\n", empty() ? "YES" : "NO");
        else
            printf("%d\n", query());
    }

    return 0;
}